package com.xyzwps.paimon.furina.modules.auth.entity

import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.upsert
import org.springframework.stereotype.Repository

@Repository
class UserPasswordRepository {

    private val table = UserPassword.Companion.TABLE

    fun save(password: UserPassword) {
        table.upsert {
            it[userId] = password.userId
            it[encryptedPassword] = password.encryptedPassword
            it[createTime] = password.createTime
            it[updateTime] = password.updateTime
        }
    }

    fun findByUserId(userId: Long): UserPassword? = table
        .select { table.userId eq userId }
        .map { UserPassword(it) }
        .firstOrNull()
}